package cn.xiangxiang.service.sms;


import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;


public class SmsConsumer implements MessageListener {

    @Value("${param}")
    private String param;

    @Autowired
    private SmsUtils smsUtils;

    @Override
    public void onMessage(Message message) {
        String msg = new String(message.getBody());
        Map map = JSON.parseObject(msg, Map.class);
        String phone = (String) map.get("phone");
        Integer code = (Integer) map.get("code");

        System.out.println(phone);
        System.out.println(code);

        /*发送短信*/
        try {
            param = param.replace("[value]", code.toString());
            smsUtils.sendSms(phone,param);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("短信发送异常");
        }

    }
}
